<?php

class Bus_Model_Bus_Row extends Zend_Db_Table_Row_Abstract
{
    public function setRoutes($routes)
    {
        $modelRoute = new Bus_Model_Route();
        // clear previous routes
        $where = $modelRoute->getAdapter()->quoteInto('bus_sid = ?', $this->bus_pid);
        $modelRoute->delete($where);

        foreach ($routes as $route) {
            $modelRoute->insert(array(
                'bus_sid' => $this->bus_pid,
                'bus_stop_sid_from' => $route['from'],
                'bus_stop_sid_to' => $route['to']
            ));
        }
    }

    public function getRoutes()
    {
        $modelRoute = new Bus_Model_Route();
        $where = $modelRoute->select()->where('bus_sid = ?', $this->bus_pid);
        $rows = $modelRoute->fetchAll($where);
        $routes = array();
        foreach ($rows as $row) {
            $routes[] = array(
                'from' => $row->bus_stop_sid_from,
                'to' => $row->bus_stop_sid_to);
        }
        return $routes;
    }
}